local buff = zbuff.create(15,6)
for i=0,14 do
    check_eq(buff[i],6,"init error")
end

local writeLen = buff:write("abcde")
check_eq(writeLen,5,"string write length error")
writeLen = buff:write(0x31,0x32,0x33,0x34,0x35)
check_eq(writeLen,5,"numbers write length error")

buff:seek(0)
local readData = buff:read(5)
check_eq(readData,"abcde","read data1 error")
readData = buff:read(5)
check_eq(readData,"12345","read data2 error")

for i=0,9 do
    buff[i] = i * 2
end

for i=0,9 do
    check_eq(buff[i],i * 2,"read byte error")
end

buff:seek(0)
writeLen = buff:pack(">bbbIAIII",1,2,3,4,"abc",666,2,3)
check_eq(writeLen,15,"pack write length error")

buff:seek(0)
local len,b1,b2,b3,b4,s,i1 = buff:unpack(">bbbIA3III")
check_eq(len,14,"pack read length error")
check_eq(b1,1,"pack read b1 error")
check_eq(b2,2,"pack read b2 error")
check_eq(b3,3,"pack read b3 error")
check_eq(b4,4,"pack read b4 error")
check_eq(s,"abc","pack read s error")
check_eq(i1,666,"pack read I error")

local buff = zbuff.create(30,0)
buff:del()
check_eq(buff:used(),0,"del error")
buff:resize(1024)
check_eq(buff:len(),1024,"resize error")
buff:copy(nil, "123")
check_eq(buff:used(),3,"copy error")
check_eq(buff:query(),"123","query error")
buff:set(1,0x30,1)
check_eq(buff:query(),"103","set error")
buff:set(0,0x30,3)
check_eq(buff:query(),"000","set error")
buff:copy(0, 0x12,0x34,0x56,0x78)
check_eq(buff:used(),4,"copy error")
check_eq(buff:query(0, 4, true),0x12345678,"query error")
check_eq(buff:query(0, 2, true),0x1234,"query error")

check_eq(buff[2],0x56,"copy error")
local buff2 = zbuff.create(16)
buff2:set(0, 0xaa)
buff2:seek(0,zbuff.SEEK_END)
buff:copy(2, buff2)
check_eq(buff:used(),18,"copy error")
check_eq(buff[3],0xaa,"copy error")
buff:del(-1)
check_eq(buff:used(),17,"del error")

buff = nil

